﻿using System;
using System.Linq.Expressions;
using SBACN.WebSite.Code;
using SBACN.WebSite.Models;

namespace SBACN.WebSite
{
    public partial class Dynamic : BasePage
    {
        public int PageFlag { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindData(1);
        }
         
        protected void BindData(int pageIndex)
        {
            string t = Request.QueryString["t"];
            if (!string.IsNullOrEmpty(t))
            {
                this.PageFlag = (pageIndex - 1) * this.Pager1.PageSize;
                int records = 0;
                Expression<Func<TB_News, bool>> f = (p => p.Type == t + "0001" && p.IsEn == false);
                Expression<Func<TB_News, DateTime>> order = (c => c.CreateDate);
                var resultQ = DAL.DALHelper.Instance.GetList<TB_News, DateTime>(f, order, false, this.Pager1.PageSize, pageIndex, out records);

                //this.List.DataSource = resultQ;
                //this.List.DataBind();
                this.Pager1.RecordCount = records;
                this.Pager1.InitControl();

                this.rptDynamic.DataSource = resultQ;
                this.rptDynamic.DataBind();
            }
        }

        protected void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
        {
            BindData(nextPage);
        }
    }
}